//
//  CLNavigationController.m
//  InterestingVideos
//
//  Created by CoderLey on 2022/8/17.
//

#import "CLNavigationController.h"

@interface CLNavigationController () <UIGestureRecognizerDelegate>

@end

@implementation CLNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    if (@available(iOS 13.0, *)) {
        self.modalPresentationStyle = UIModalPresentationFullScreen;
        UINavigationBar *navigationBar = [UINavigationBar appearance];
        
        UINavigationBarAppearance *scrollEdgeAppearance = [[UINavigationBarAppearance alloc] init];
        scrollEdgeAppearance.backgroundColor = RGBA(249, 250, 252, 1);
        navigationBar.scrollEdgeAppearance = scrollEdgeAppearance;
        [scrollEdgeAppearance setTitleTextAttributes:@{NSForegroundColorAttributeName:RGB(12, 12, 12),NSFontAttributeName:[UIFont systemFontOfSize:18 weight:UIFontWeightMedium]}];
//        scrollEdgeAppearance.shadowImage = [JKAPPUtils getStretchCenterPointImage:KImageNamed(@"ic_nav_bg")];
        scrollEdgeAppearance.backgroundImage = KImageNamed(@"ic_nav_bg");
        [scrollEdgeAppearance setShadowImage:[UIImage new]];
        navigationBar.standardAppearance = scrollEdgeAppearance;
    }else{
        
    }
    self.navigationBar.barTintColor = RGBA(249, 250, 252, 1);
    self.navigationBar.tintColor = RGB(12, 12, 12);
    self.navigationBar.translucent = NO;
    [self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:RGB(12, 12, 12),NSFontAttributeName:[UIFont systemFontOfSize:18 weight:UIFontWeightMedium]}];
    UIBarButtonItem *barItemInNavigationBarAppearanceProxy = [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UINavigationBar class]]];
    [barItemInNavigationBarAppearanceProxy
     setTitleTextAttributes:[NSDictionary
                             dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17.f], NSFontAttributeName,RGB(12, 12, 12),NSForegroundColorAttributeName,nil] forState:UIControlStateNormal];
    
    
//   // 隐藏导航栏线条
    [[UINavigationBar appearance] setBackgroundImage:KImageNamed(@"ic_nav_bg") forBarMetrics:UIBarMetricsDefault];
//    [[UINavigationBar appearance] setShadowImage:KImageNamed(@"ic_nav_bg")];
//    [self.navigationBar setBackgroundImage:[JKAPPUtils getStretchCenterPointImage:KImageNamed(@"ic_nav_bg")] forBarMetrics:UIBarMetricsDefault];
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.interactivePopGestureRecognizer.enabled = NO;
    }
    if (self.pushViewControllBlock) {
        self.pushViewControllBlock();
    }
    if (self.childViewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
    }
    [super pushViewController:viewController animated:YES];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self forbiddenSideBack];
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self resetSideBack];
}

#pragma mark -- 禁用边缘返回
-(void)forbiddenSideBack{

    self.isCanBack = NO;

     //关闭ios右滑返回

    if([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {

        self.interactivePopGestureRecognizer.delegate=self;

    }

}

#pragma mark --恢复边缘返回
- (void)resetSideBack {

    self.isCanBack=YES;

    //开启ios右滑返回

    if([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {

        self.interactivePopGestureRecognizer.delegate = nil;

    }

}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer {

    return self.isCanBack;

}


@end
